<template>
  <van-row>
    <div class="top"></div>
    <div v-for="(item,index) in paperList" :key="index" style="margin-bottom: 20px">
      <van-panel :title="item.title"  status="已完成">
        <div style="background-color: #fcfcfc;padding-bottom: 20px;">
          <div v-for="(question,index) in questions" style="margin-bottom: 10px;text-align: center">
          <div class="questions">{{index+1}}:{{question.content}}</div>
          <div class="answer">
            <span v-for="(answer) in item.content.answers[index]">
              {{answer}}
            </span>
          </div>
          </div>
        </div>
      </van-panel>
    </div>
    <div class="bottom"></div>
  </van-row>
</template>

<script>
  import {baseUrl} from '../constants'
  import {paper} from '../constants'

  export default {
  name: 'datas',
  data () {
    return {
      paperList:[],
      user:{},
      userID:'',
      paperKey:'',
      questions:[],
    }
  },
    mounted(){
      this.user=this.$store.state.user;
      this.userID=this.user.id;
      if(this.userID){
        this.axios.get(baseUrl.serverUrl+'/user/answer?id='+this.userID).then(res=>{
          if(res.data.status==1){
            //获取答题记录
            this.paperList = res.data.data;
            this.paperList.forEach(data=>{
              data.content=JSON.parse(data.content);
              let time = new Date(data.createTime);
              data.createTime = time.getFullYear()+'年'+(time.getMonth()+1)+'月'+time.getDate()+'日'+time.getHours()+'点';
              this.paperKey=data.content.type;
              this.questions = paper[this.paperKey];
              if(data.content.type=='primary'){
                data.title='小学组';
              }else if(data.content.type='middle'){
                data.title='中学';
              }else if(data.content.type='height'){
                data.title='高中组'
              }else {
                data.title='大学'
              }
            })
          }
        })
      }
    },
  methods: {

  }
}
</script>

<style scoped>
</style>
